package org.come.xingpan;

import org.come.Frame.TestpackJframe;
import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.mouslisten.GoodsMouslisten;
import org.come.until.EquipTool;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.MessagrFlagUntil;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MouseListenerStarCardMain extends MouseAdapter {

    private int i;
    private JpanelXingCardMain jpanelXingCardMain;
    private JpanelXingBackMain jpanelXingBackMain;

    public MouseListenerStarCardMain(int i, JpanelXingCardMain jpanelXingCardMain) {
        this.i = i;
        this.jpanelXingCardMain = jpanelXingCardMain;
    }

    public MouseListenerStarCardMain(int i, JpanelXingBackMain jpanelXingBackMain) {
        super();
        this.i = i;
        this.jpanelXingBackMain = jpanelXingBackMain;
    }

    @Override
    public void mousePressed(MouseEvent e) {

        // 获取选中的星卡
        Goodstable starCardGoods = GoodsListFromServerUntil.getStarCardGoods(i);
        // 判断鼠标是否是加锁图标
        if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE10)) {
            MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            // 判断物品是否为空
            if (starCardGoods != null) {
                if (EquipTool.isEquip(starCardGoods.getType())) {
                    if (starCardGoods.getGoodlock() == 1) {
                        ZhuFrame.getZhuJpanel().addPrompt("该物品已加锁");
                    } else {
                        starCardGoods.setGoodlock(1);
                        GoodsMouslisten.gooduse(starCardGoods, 0);
                        ZhuFrame.getZhuJpanel().addPrompt("加锁成功");
                    }
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt("该类型物品不可加锁");
                }
            }
        } else if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE11)) {
            // 判断鼠标是否是解锁图标
            if (starCardGoods != null) {// 判断物品是否为空//判断物品是否加锁
                if (starCardGoods.getGoodlock() == 1) {// 已加锁
                    starCardGoods.setGoodlock(0);
                    GoodsMouslisten.gooduse(starCardGoods, 0);
                    ZhuFrame.getZhuJpanel().addPrompt("解锁成功");
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }
        } else if (starCardGoods != null && jpanelXingCardMain != null) {
            if (jpanelXingCardMain.getBigType() == 1) {
                //     jpanelXingCardMain.attributeImgShow(starCardGoods);
            } else if (jpanelXingCardMain.getBigType() == 2) {
//                jpanelXingCardMain.chooseStarCardImg(starCardGoods);
//                if (jpanelXingCardMain.getSmallType() != 3)
//                    jpanelXingCardMain.viewChange(starCardGoods);
            }
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        Goodstable goodstable = GoodsListFromServerUntil.getStarCardGoods(i);
        if (goodstable != null) {
            ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        TestpackJframe.getTestpackJframe().getJpac().ClearText();
        ZhuFrame.getZhuJpanel().cleargoodtext();
    }

}
